######################################################################
# Time-stamp: <03/11/03 17:26:06 ostolop>
#
# Some legacy routines to deal with EP datasets and folders
#
# Initially written by Jaak Vilo
######################################################################
package EP::Legacy::EPDATA;
use EP::Config;

our $EPCLUST_WWW      = $EP::Config::h->{EPCLUST_WWW_URL};
our $EPCLUST_DB_PATH  = $EP::Config::h->{EPCLUST_DB_PATH};

######################################################################
# defines the available EP datasets, hardcoded --> should probably be
# either written in an XML file somewhere, or retrieved from a DB.
#
# src: Programs/EPlib/EPCLUST_lib/lib.header.pl
######################################################################
sub define_available_data_sets {
  %ORGANISM = (
	       "Yeast" =>      "Saccharomyces cerevisiae",
	       "Mouse" =>      "Mus musculus",
	       "Hughes" =>     "Saccharomyces cerevisiae",
	       "ACE" =>        "C. elegans",
	       "EST" =>        "EST-s (tmp)",
	       "Human" =>      "Homo sapiens",
	       "Leish" =>      "Leishemania",
	      );

  @ORGANISMS = qw( Yeast );

  @{$DATASETS{'Yeast'}} = qw( Pat_Brown
			      Adaptive_evolution_Ferea
			      Cellcycle_Spellman
			      Diauxic_shift_DeRisi
			      MAPK_signaling_Roberts
			      Protein_folding_Travers
			      Stress_response_Gasch
			    );

 # not finished yet... have to be put back again
#			      Rick_Young_Yeast
#			      Test_and_Demo

#  @{$DATASETS{'Mouse'}} = qw( mouse_tissue_49 );
#  @{$DATASETS{'Human'}} = qw( fig2clusterdata Cancer );

#  @{$DATASETS{'ACE'}} = qw( MISSING );
#  @{$DATASETS{'EST'}} = qw( EST_data );

#  @{$DATASETS{'Leish'}} = qw( Leish_Combined Leish_Donovani
#			      Leish_Major Leish_German LDonovani
#			      LMajor German LD_and_LM Leish_first
#			    );

#  @{$DATASETS{'Rat'}} = qw( Rat1 );
#  @{$DATASETS{'Hughes'}} = qw( data_ratio );
}

######################################################################
# outputs dataset options/links for a particular organism/dataset pair
#
# src: Programs/EPlib/EPCLUST_lib/lib.data_selection_from_DB_files.pl
######################################################################
sub output_option {
  my($ORGANISM, $DS, $opt) =@_;

  my $CHECKED = "";
  $CHECKED = " CHECKED" if (defined ($opt) and $opt eq 'SELECTED');

#  print "<TR><TH COLSPAN=4>Error: Data set '$EPCLUST_DB/$ORGANISM/$DS' is missing!</TH></TR>\n" 
#    and return "ERROR" unless -f "$EPCLUST_DB/$ORGANISM/$DS.data" ; 

  my $s = <<__EOF__;
<TR>
<TH width="5%"><INPUT TYPE=radio NAME=DATASET VALUE=DATASET:$ORGANISM:$DS$CHECKED></TH>
<TD width="35%"><B><A HREF="$EPCLUST_WWW/DB/$ORGANISM/$DS.data">$DS</A></B></TD>
<TD width="30%"><A HREF="$EPCLUST_WWW/DB/$ORGANISM/$DS.experiments">column titles</A></TD>
<TD width="30%"><A HREF="$EPCLUST_WWW/DB/$ORGANISM/$DS.names">gene annotations</A></TD>
</TR>
__EOF__

  return $s;
}

######################################################################
######################################################################
######################################################################


#
# What are the general fields that need to be processed?
#

sub output_epclust_header
{
	
	$myurl = "http://$EP_HOST" . $Q->url( -absolute=>1 ) ;
	
	# index.cgi/DATADIR/
	# print $Q->redirect( $Q->url() . "/data/$where" ) ;
	
	print $Q->header();
	
	&print_header("EPCLUST", "Clustering, visualization, and analysis", "$EPCLUST_WWW", "EPCLUST.html") ;

}





sub extract_orfnames
{
	@ORFNAMES = split( /\s/ , $QUERY{'ORFNAMES'} ) ;
}


sub set_global_variables
{
	######################################################################
	# Some global variables ...
	######################################################################
	
	$QUERY{'FOLDER'}    = filename_clean( $QUERY{'FOLDER'}    , 'base' ) ;
	$QUERY{'NEWFOLDER'} = filename_clean( $QUERY{'NEWFOLDER'} , 'base' ) ;
	$QUERY{'DATANAME'}  = filename_clean( $QUERY{'DATANAME'}  , 'base' ) ;
	$QUERY{'NEWDATA'}   = filename_clean( $QUERY{'NEWDATA'}   , 'base' ) ;
	
	$FOLDER   = $QUERY{"FOLDER"};
	$DATANAME = $QUERY{"DATANAME"};
	
	$ABSOLUTE_FOLDER = "$EPCLUST_PREF/DATA/$FOLDER" ;
	$ABSOLUTE_DATA   = "$ABSOLUTE_FOLDER/$DATANAME" ;
	
	$datafile = $ABSOLUTE_DATA ;

        srand( time() ^ ( $$ + ($$ << 15 ))  ) ;
        @alfab = ( 'a'..'z' , 'A'..'Z' ) ;
        foreach ( 1..5 ) { $randstr .= @alfab[ rand( scalar(@alfab) ) ] ; }

	$DEBUG_HIDDEN = $DEBUG_HIDDEN_URL = ""; 
	$DEBUG = $Q->param('DEBUG') if defined $Q->param('DEBUG');
	$DEBUG_HIDDEN = qq(<INPUT TYPE="HIDDEN" NAME="DEBUG" VALUE="$DEBUG">)  if $DEBUG ;
	$DEBUG_HIDDEN_URL = "&DEBUG=$DEBUG" ; 

	$QUERY{'TITLES'} = "AUTO" unless $QUERY{'TITLES'} ; 

	$PRINT_COLUMN_ID = $PRINT_ROW_ID   = $PRINT_TITLES_URL = ""; 
	$PRINT_COLUMN_ID = 1 if $QUERY{'TITLES'} eq "COLUMNS" || $QUERY{'TITLES'} eq  "BOTH" ; 
	$PRINT_ROW_ID    = 1 if $QUERY{'TITLES'} eq "ROWS"    || $QUERY{'TITLES'} eq  "BOTH" ;
	$PRINT_TITLES_AUTO = 1 if $QUERY{'TITLES'} eq 'AUTO' ; 
	$PRINT_TITLES_URL    = "&TITLES="    .  ($QUERY{'TITLES'} ) if $QUERY{'TITLES'} ;
	$PRINT_TITLES_HIDDEN = qq(<INPUT TYPE="HIDDEN" NAME="TITLES=" VALUE="$QUERY{'TITLES'}">) if $QUERY{'TITLES'} ; 

}

sub DATA_HIDDEN_SPEC
{
	$DATA_HIDDEN_SPEC = "" ; 
	$DATA_HIDDEN_SPEC .= "$DEBUG_HIDDEN\n" if $DEBUG ; 
        $DATA_HIDDEN_SPEC .= qq(<INPUT TYPE="HIDDEN" NAME="FOLDER" VALUE="$FOLDER">\n) if $FOLDER =~ /\S/ ; 
	$DATA_HIDDEN_SPEC .= qq(<INPUT TYPE="HIDDEN" NAME="DATANAME" VALUE="$DATANAME">\n) if $DATANAME =~ /\S/ ;
	$DATA_HIDDEN_SPEC .= "$DEBUG_HIDDEN\n" if $DEBUG ; 
	$DATA_HIDDEN_SPEC ; 
}


######################################################################
#
######################################################################

1;
